﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace CungMuaC5.WebUC
{
    public partial class wucDanhSachAll : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BUS_KhuyenMai bus_KhuyenMai = new BUS_KhuyenMai();
                int makhuvuc = Session.GetDiaDiem()+1;
                BUS_KhuVuc bus_kv = new BUS_KhuVuc();
                List<DTO_KhuyenMai> list;
                int nKV = bus_kv.SelectAll().Count;
                if(makhuvuc>nKV)
                    list = bus_KhuyenMai.SelectAll();
                else
                    list = bus_KhuyenMai.SelectAll(makhuvuc);
                List<DTO_ChiTietKM> listChiTiet = new List<DTO_ChiTietKM>();
                for (int i = 0; i < list.Count; i++)
                {
                    DTO_ChiTietKM km = new DTO_ChiTietKM();
                    km.TenKM = list[i].TenKM;
                    km.MaKM = list[i].MaKM;
                    km.DonGiaCu = list[i].DonGiaCu;
                    km.DonGiaMoi = list[i].DonGiaMoi;
                    km.HinhAnh = list[i].HinhAnh;
                    km.SoNguoiCungMua = bus_KhuyenMai.laySoLuongDatHang(list[i].MaKM);
                    listChiTiet.Add(km);
                }
                DataListAll.DataSource = listChiTiet; 
                DataListAll.DataBind();
            }
        }

    }
}